using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace WisdriContactsAndroid
{
    [Activity(Label = "部门", MainLauncher = false)]			
    public class Department : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Department);

            var listView = FindViewById<ListView>(Resource.Id.listViewDepartment);

            var personList = SQLiteHelper.GetPersonData();
            listView.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, 
                personList.GroupBy(p => p.DEPARTMENT).Select(p => p.Key).ToArray());  
                     
            listView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
            {
                Activity act = this as Activity;
                Intent intent = new Intent();  
                intent.SetClass(act, typeof(ContactList));  
               
                Bundle b = new Bundle();  
                b.PutString("department", (e.View as TextView).Text);
                intent.PutExtras(b);

                act.StartActivity(intent);  
            };

        }
    }
}

